<?php
namespace app\Admin\controller;
use think\Controller;
use think\Db;
use think\Session;
use think\Cache;
use think\Request;
use think\Loader;
use think\Validate;
use Qiniu\Auth;
use Qiniu\Storage\BucketManager;
use Qiniu\Storage\UploadManager;

class Code extends Controller
{
/**
    **客户端的二微码
    **/
    public function versionCode()
    {
        $adminUser = Session::get('adminUser');
        $this->assign('adminUser',$adminUser);

        return $this->fetch();
    }

    /**
    *   生成客户端的二维码
    **/
    public function versionQrcode()
    {
        $app = input('get.app');
        if($app) {        
            //生成当前的二维码
            $qrCode = new \Endroid\QrCode\QrCode();       
            //想显示在二维码中的文字内容，这里设置了一个查看文章的地址
            $url = 'http://api.zgyejy.net/index.php/admin/code/versionQrcodes?app='.$app;
            $qrCode->setText($url)
                ->setSize(300)
                ->setPadding(10)
                ->setErrorCorrection('high')
                ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
                ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0))
                ->setLabel('')
                ->setLabelFontSize(16)
                ->setImageType(\Endroid\QrCode\QrCode::IMAGE_TYPE_PNG);
             $qrCode->render();
             // var_dump($qrCode->render());
        }
    }

    public function versionQrcodes()
    {
        $app = input('get.app');
        
        $version = Db('version_upgrade')
                    ->where('app_id',$app)
                    ->order('id desc')
                    ->order('version_code desc')
                    ->order('create_time desc')
                    ->find();
        // var_dump($version);
        if($version){

            $file['app'] = 'http://api.zgyejy.net'.$version['version_url'];
            // var_dump($file['app']);die;

            // return $file;        
        }
         $this->assign('file',$file);
        return $this->fetch(); 
        
    }

}